package sd.czw.com.mmgapp.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ContextThemeWrapper;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import sd.czw.com.mmgapp.R;

/**
 * Created by czw
 * desc 描述：我的推广
 * on 2017/7/15.
 */
public class TGActivity extends AppCompatActivity {

    @Bind(R.id.rl_back)
    RelativeLayout rlBack;
    @Bind(R.id.tv_dp)
    TextView tvDp;
    @Bind(R.id.rl_dp)
    RelativeLayout rlDp;
    @Bind(R.id.tv_yqm)
    TextView tvYqm;
    @Bind(R.id.rl_yqm)
    RelativeLayout rlYqm;
    @Bind(R.id.tv_wz)
    TextView tvWz;
    @Bind(R.id.tv_mp)
    TextView tvMp;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.rl_wz)
    RelativeLayout rlWz;
    @Bind(R.id.rl_mp)
    RelativeLayout rlMp;
    private ClipData mClipData;
    private ClipboardManager mClipboardManager;
    private  AlertDialog.Builder builder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tg);
        ButterKnife.bind(this);
        mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    }

    @OnClick({R.id.rl_back,R.id.rl_dp,R.id.rl_wz})
    void onclick(View view){
        switch (view.getId()){
            case R.id.rl_back:
                onBackPressed();
                break;
            case R.id.rl_dp:
                final String s = tvDp.getText().toString();
                builder = new AlertDialog.Builder(new ContextThemeWrapper(this,R.style.AlertDialogCustomhhh));
                builder.setTitle("复制到粘贴板" )
                        .setPositiveButton("复制", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //创建一个新的文本clip对象
                                mClipData = ClipData.newPlainText("Simple test", s);
                                //把clip对象放在剪贴板中
                                mClipboardManager.setPrimaryClip(mClipData);
                                Toast.makeText(getApplicationContext(), "文本已经复制成功！",
                                        Toast.LENGTH_SHORT).show();
                                dialogInterface.dismiss();
                            }
                        }).setNegativeButton("取消",null)
                        .show();
                break;
            case R.id.rl_wz:
                final String url = "http://www.baidu.com/";
                builder = new AlertDialog.Builder(new ContextThemeWrapper(this,R.style.AlertDialogCustomhhh));
                builder.setTitle(url)
                        .setItems(new String[]{"打开链接", "复制链接", "取消"}, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int i) {
                                switch (i){
                                    case 0:
                                        Intent intent=new Intent();//创建Intent对象
                                        intent.setAction(Intent.ACTION_VIEW);//为Intent设置动作
                                        intent.setData(Uri.parse(url));//为Intent设置数据
                                        startActivity(intent);//将Intent传递给Activity
                                        dialog.dismiss();
                                        break;
                                    case 1:
                                        mClipData = ClipData.newPlainText("Simple test", "sd");
                                        //把clip对象放在剪贴板中
                                        mClipboardManager.setPrimaryClip(mClipData);
                                        Toast.makeText(getApplicationContext(), "链接已经复制成功！",
                                                Toast.LENGTH_SHORT).show();
                                        dialog.dismiss();
                                        break;
                                    case 2:
                                        dialog.dismiss();
                                        break;
                                }
                            }
                        }
                ).show();
                break;
        }
    }
}
